﻿using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Audio;
using Microsoft.Xna.Framework.Content;
using Microsoft.Xna.Framework.Graphics;
using Microsoft.Xna.Framework.Input;
using Microsoft.Xna.Framework.Media;

namespace Game1942
{
    public class MainMenu : State
    {
        private MenuComponent menuPrincipal;
        private SoundEffect startSound;
        private Music music;
        private Song menuMusic;

        public MainMenu(GameContext screen, ContentManager contentManager, GraphicsDevice graphicsDevice)
        {
            this.screen = screen;
            content = contentManager;
            this.graphicsDevice = graphicsDevice;
            Initialize();
        }

        protected void Initialize()
        {
            menuPrincipal = new MenuComponent(screen, Color.Red, Color.DarkGray, new Vector2(250, 150), content.Load<SpriteFont>("Fonts/Menu"), 40,
                content);
            menuPrincipal.AddElement("New Game");
            menuPrincipal.AddElement("Load Game");
            menuPrincipal.AddElement("Options");
            menuPrincipal.AddElement("High Scores");
            menuPrincipal.AddElement("Exit");
            startSound = content.Load<SoundEffect>("Sounds/Start");
            menuMusic = content.Load<Song>("Sounds/MenuMusic");
            music = new Music();
            music.PlayMusic(menuMusic);
        }


        public override void Update(GameTime gameTime)
        {
            menuPrincipal.PressKeys(Keyboard.GetState());
            if (Keyboard.GetState().IsKeyDown(Keys.Enter))
            {
                switch (menuPrincipal.ElementActive())
                {
                    case 1:
                        screen.State = new Game(screen, content, graphicsDevice, false);
                        break;
                    case 2: 
                        screen.State = new Game(screen, content, graphicsDevice, true);
                        break;
                    case 5:
                        screen.Exit();
                        break;
                } 
                startSound.Play();
            }
        }

        public override void Draw(GameTime gameTime)
        {
            screen.Graphics.GraphicsDevice.Clear(Color.Black);

            menuPrincipal.Draw(screen.SpriteBatchField);
        }
    }
}
